//
//  UIPageControlDemo.swift
//  firstProject
//
//  Created by 张彦辉 on 2017/3/26.
//  Copyright © 2017年 张彦辉. All rights reserved.
//

import UIKit

class UIPageControlDemo: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.gray
        let page:UIPageControl = UIPageControl(frame: CGRect(x: 100, y: 100, width: 100, height: 30))
        //设置分页的总页数
        page.numberOfPages = 5
        //设置当前是第几页
        page.currentPage = 2
        //设置只有一页时不显示
        page.hidesForSinglePage = true
        //设置当前页颜色
        page.currentPageIndicatorTintColor = UIColor.red
        //设置分页点颜色
        page.pageIndicatorTintColor = UIColor.black
        //添加方法
        page.addTarget(self, action: #selector(changeValue(page:)), for: .valueChanged)
        self.view.addSubview(page)

    }
    func changeValue(page:UIPageControl) -> Void {
        print(page.currentPage)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
